package com.suse.service.cos.service.impl;

import com.suse.common.config.response.ApiException;
import com.suse.common.config.response.R;
import com.suse.common.util.cos.CosUtil;
import com.suse.service.cos.service.FileService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class FileServiceImpl implements FileService {

    @Override
    public R uploadFile(MultipartFile file) {
        String url = CosUtil.upload(file);
        return R.put("url",url).success();
    }

    @Override
    public R removeFile(String url) {
        if (CosUtil.delete(url)) {
            return R.success("删除成功");
        }else {
            throw new ApiException("删除失败！");
        }
    }
}
